/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simpledraw;

import java.awt.Graphics;
import java.awt.Point;
import java.util.Iterator;

/**
 *
 * @author renatocardoso
 */
public class RectangleShape extends Shapes
{
  Point sPoint = null;
  Point ePoint = null;
  
    @Override
  public void draw(Graphics g)
  {
    Iterator it = getList().iterator();
    //if the list does not contain the required two points, return.
    if(getList().size() < 2)
    {
      return;
    }
    sPoint = (Point)it.next();
    ePoint = (Point)it.next();
    if(sPoint == null || ePoint == null)
    {
      return;
    }
	
    int x = (int)sPoint.getX();
    int y = (int)sPoint.getY();
    int width = (int)(ePoint.getX()-sPoint.getX());
    int height=(int)(ePoint.getY()-sPoint.getY()) ;
    
    if (width < 0) {
        width = 0 - width;
        x = x - width + 1;
        if (x < 0) {
            width += x;
            x = 0;
        }
    }
    if (height < 0) {
        height = 0 - height;
        y = y - height + 1;
        if (y < 0) {
            height += y;
            y = 0;
        }
    }

    else
    {
        g.drawRect(x, y, width,height);
    }//end of if
    //getList().clear();
  }//end of draw for rectangle


}//rectangle
